using System;
using Unity.VisualScripting;
using GameFramework;
using GameFramework.Download;

namespace LS.UGFUnits
{
    [UnitSurtitle("Download")]
    [UnitShortTitle("Get All Info")]
    public sealed class GetAllDownloadInfo : DownloadUnit
    {
        [DoNotSerialize]
        public ValueOutput AllInfo { get; private set; }
        
        [DoNotSerialize]
        public ValueOutput Count { get; private set; }
        
        protected override void Definition()
        {
            base.Definition();
            AllInfo = ValueOutput<TaskInfo[]>(nameof(TaskInfo));
            Count = ValueOutput<int>(nameof(Count));
        }
        protected override ControlOutput In(Flow flow)
        {
            TaskInfo[] infos = Target?.GetAllDownloadInfos() ?? Array.Empty<TaskInfo>();
            flow.SetValue(AllInfo, infos);
            flow.SetValue(Count, infos.Length);
            return Output;
        }
    }
}